import java.util.Arrays;
import java.util.Scanner;

public class Main1858 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        int a=0;
        for (int i=0;i<n;i++){
            if (arr[ i]%x!=0) {
                a=a+1;
            }
        }
        int[] arr_new = new int[a];
        int m=0;
        for (int i = 0; i <n; i++) {
            if (arr[i] % x != 0) {
                arr_new[m]=arr[i];
                m++;
            }
        }
        for (int i=0;i<m;i++) {
            if (arr_new[i] >= 65 && arr_new[i] <= 90) {
                System.out.print((char) arr_new[i] + " ");
            } else {
                System.out.print(arr_new[i] + " ");
            }
        }
    }
}
